package vno.fux.res.pool
{
	import flash.display.Bitmap;
	import flash.utils.Dictionary;
	
	import vno.fux.res.manager.LoadState;
	import vno.fux.res.manager.ResourceManager;

	public class NpcResource extends Resource
	{
		use namespace RM_CRM;
		RM_CRM var _pic:AutoBitmap;
		RM_CRM var _face:AutoBitmap;
		public function NpcResource(id_:uint, setting:XML)
		{
			super(id_);
		}

		override public function create():void
		{
			this._loadStateDic = new Dictionary(true);
			initPic();
		}
		private function initPic():void
		{
			_pic = new AutoBitmap;
			_face = new AutoBitmap;
			this._loadStateDic[_face] = LoadState.NOT_LOAD;
			this._loadStateDic[_pic] = LoadState.NOT_LOAD;
		}

		override public function destroy():void
		{
			destroyPic();
			destroyFace();
			this._loadStateDic = null;
		}
		private function destroyFace():void
		{
			_face.detachAll();
			_face.dispose();
			_face = null;
		}
		private function destroyPic():void
		{
			_pic.detachAll();
			_pic.dispose();
			_pic = null;
		}

		public function get pic():AutoBitmap
		{
			if(_loadStateDic[_pic] == LoadState.NOT_LOAD)
			{
				_loadStateDic[_pic] = LoadState.PRE_LOAD;
				ResourceManager.getInstance().cha.load(id);
			}
			return _pic;
		}
	}
}